package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

@Mapper
public interface CategoryMapper {
    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    Page<Category> pagelist(CategoryPageQueryDTO categoryPageQueryDTO);


    /**
     * 添加分类
     * @param category
     */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into sky_take_out.category (type, name, sort, status, create_time, update_time, create_user, update_user) values" +
            " (#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser});")
    void insertCategory(Category category);

    /**
     * 更新修改分类
     * @param category
     */
  //  @Update("update sky_take_out.category set name=#{name},sort=#{sort},type=#{type} where id=#{id}")
    @AutoFill(value = OperationType.UPDATE)
    void update(Category category);



    Category[] listByCategory(Integer type);

    @AutoFill(value = OperationType.UPDATE)
    void updateStatus(Category category);

    @Delete("delete from sky_take_out.category where id=#{id}")
    void deleteById(Long id);

    /**
     * 根据主键category的id查找
     * @param id
     * @return
     */
    @Select("select * from sky_take_out.category where id=#{id};")
    Category getById(Long id);
}
